<div class="row">
<div class="panel"><h6>Manage Employees / Edit Employee</h6></div>
	<?if(isset($system_message))echo $system_message;?>
	<?php 
		if(!empty($output)) echo $output->output;
	?>
</div>
<script>
	$(document).ready(function(){
		$('a#change_employee_password').on('click',function(e){
			e.preventDefault();
			
			// var new_div = document.createElement("div");
			// new_div.id = 'msgDialog';
			$( "#msgDialog" ).on( "dialogbeforeclose", function( event, ui ) {
            	$("#msgDialog > div.content").empty();
        	} );
        	
			var url = $(this).attr('href');

	        $("#msgDialog").dialog('option','width',400);
	        $("#msgDialog").dialog('option','height',350);
			$("#msgDialog").dialog('option','title','Change Password.');
	        $("#msgDialog").dialog('option', 'buttons', {
	        "Cancel" : function() {
					$(this).dialog("close");
	            }
	        });

	        var form = '';
	        	form += '<form id="delete_student_form" action="'+ url +'" method="post" autocomplete="off">';
	        	form += '<span class="small-info">Password and Confirm Password must be the same, minimum of 4 characters alphanumeric, spaces will be automatically removed.</span><hr class="clearfix">';
	        	form += '<label>Password</label><input id="password" type="text" name="pass" placeholder="Password" title="User Password" required>';
	        	form += '<label>Confirm Password</label><input id="user_password" type="text" name="c_pass" placeholder="Confirm Password" title="Confirm User Password" required>';
	        	form += '<br>';
	        	form += '<input type="submit" name="delete" value="Process Change Password" class="btn btn-danger">';
	        	form += '</form>';
	        $("#msgDialog > div.content").html(form);
	        $("#msgDialog").dialog("open");

		});


		$(document).on('submit','form#delete_student_form',function(e){

		        	e.preventDefault();

		        	var password = $(this).find('#password').val();
		        	var c_password = $(this).find('#user_password').val();
		        	var url = $(this).attr('action');

		        	if(password == c_password && password.length >=4 && c_password.length >=4 )
		        	{
		        	$.ajax({
		        		method:'POST',
		        		url:url,
		        		data:$(this).serialize()
		        	}).done(function(e){
		        		if(e == 1)
		        		{
		                 alert('Password successfully changed.');
		        		}else if(e == 2)
		        		{
		                 alert('Unable to change employee password.');
		        		}else if(e == 3){
		        		 alert('The password should not contain the username. Please try again.');	
		        		}

		        	}).fail(function(){
		                  alert('error Occured changing of password failed, unable to establish connection with server.');
		        	}).always(function(){
		                $('#msgDialog').dialog("close");
		            });

		        	}else{
						alert('Password and Confirm password must be the same, minimum of 4 characters.'); 
		        	}
		        });
	});
</script>